package com.example.yunifang;

import java.util.Timer;
import java.util.TimerTask;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;

public class WelcomeActivity extends Activity {

	private Timer timer;
	private int count;
	private Handler handler=new Handler(){
		@SuppressLint("NewApi")
		public void handleMessage(android.os.Message msg) {
			count = msg.arg1;
			if(count==3){
				Intent intent=new Intent(WelcomeActivity.this,DaoHangActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.outactivity, R.anim.inactivity);
				finish();
			}
		};
	};
	private RelativeLayout re;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_welcome);
		if(timer==null){
			timer=new Timer();
			timer.schedule(new TimerTask() {
				int count=0;
				@Override
				public void run() {
					// TODO Auto-generated method stub
					Message msg=Message.obtain();
					msg.arg1=count;
					handler.sendMessage(msg);
					count++;
				}
			}, 0, 1000);
		}
		re=(RelativeLayout)findViewById(R.id.re);
		re.setOnClickListener(new OnClickListener() {
			@SuppressLint("NewApi")
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
					Intent intent=new Intent(WelcomeActivity.this,DaoHangActivity.class);
					startActivity(intent);
					overridePendingTransition(R.anim.outactivity, R.anim.inactivity);
					timer.cancel();
					finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.welcome, menu);
		return true;
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if(timer!=null){
			timer.cancel();
		}
	}

}
